package com.ruicar.afs.cloud.product.vo;

import com.ruicar.afs.cloud.product.enums.ATOM_CONTROL_TYPE;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;

/**
 * @author changyu.gui
 * @version 1.0
 * @date 2020/5/14 0:41
 */
@Data
@NoArgsConstructor
public class VueJs {
    @ApiModelProperty(value = "字段key")
    @NotBlank(message = "字段key不能为空")
    private String key;

    @ApiModelProperty(value = "字段标题")
    @NotBlank(message = "字段标题不能为空")
    private String title;

    @ApiModelProperty(value = "组件类型")
    @NotBlank(message = "组件类型不能为空")
    private String type;

    @ApiModelProperty(value = "数据字典")
    private String dicKey;

    @ApiModelProperty(value = "数据字典数据")
    private String[] dicData;

    @ApiModelProperty(value = "校验规则")
    private String[] rules;

    @ApiModelProperty(value = "最大输入长度,默认100")
    private Integer maxlength;

    @ApiModelProperty(value = "是否只读")
    private Boolean readOnly;

    @ApiModelProperty(value = "是否必填")
    private Boolean require;

    @ApiModelProperty(value = "表格宽度 默认120")
    private Number labelWidth = 250;

    @ApiModelProperty(value = "类型为number和currency时有效默认 2")
    private Number scale;

    @ApiModelProperty(value = "宽度 默认120")
    private Number width;

    @ApiModelProperty(value = "字段对应表格header最小宽度")
    private Number minWidth;

    @ApiModelProperty(value = "字段对应表格header最大宽度")
    private Number maxWidth;

    @ApiModelProperty(value = "表列是否可拖动,默认false")
    private Boolean resizable;

    @ApiModelProperty(value = "默认是否显示字段对应列,组件为表格时有效 默认值 true")
    private Boolean columnShow;

    @ApiModelProperty(value = "表格header对齐方式,默认center")
    private String align;

    @ApiModelProperty(value = "字段样式")
    private String fixed;

    @ApiModelProperty(value = "插槽")
    private String slot;

    public VueJs(ProductPlanVo vo) {
        BeanUtils.copyProperties(vo, this);
        switch (this.getType()) {
            case "06": {
                this.setScale(0);
                break;
            }
            default:
                break;
        }
        this.setType(StringUtils.isNotEmpty(ATOM_CONTROL_TYPE.getType(this.getType())) ? ATOM_CONTROL_TYPE.getType(this.getType()) : this.getType());
    }
}
